<template>
    <div>
        <div class="title">
            我的
        </div>
        <div class="user-info">
            <div class="left">
                <img :src="userInfo.avatar" v-if="userInfo.avatar">
            </div>
            <div class="right">
                <div class="nickname">
                    {{ userInfo.nickname }}
                </div>
                <div class="phone-number">
                    {{ (userInfo.phoneNumber) }}
                </div>
            </div>
        </div>

        <div class="nav-list">
            <van-cell v-for="item in navList" :key="item.name" :title="item.name" is-link :to="item.path" />
        </div>
    </div>
</template>

<script>
import user from '@/api/user'
import NavBar from '@/components/navbar/NavBar.vue'
export default {
    components: {
        NavBar
    },
    data() {
        return {
            userInfo: null,
            navList: [
                {
                    name: '我的地址',
                    path: '/address/myAddress'
                },
                {
                    name: '我的收藏',
                    path: '/collection/myCollection'
                },
                {
                    name: '我的评论',
                    path: '/comment/myComment',
                }
            ]
        }
    },
    created() {
        this.getUserInfo()
    },
    methods: {
        getUserInfo() {

            user.getUserInfo()
                .then(res => {
                    if (res.code == 200) {
                        this.userInfo = res.data.user
                    }
                    else {
                        alert("出错了")
                    }
                })
        }
    }
}
</script>

<style scoped>
.title {
    font-size:16px;
    font-weight: 800;

    padding:10px 0 20px 0;
    background-color: rgb(25, 137, 250);

    color:white;
}

.user-info {
    display: flex;

    align-items: center;

    padding: 10px;

    font-weight: 600;

    background-color: rgb(25, 137, 250);

    color: white;

    font-size: 16px;
}

.user-info img{
    width: 80px;
    height: 80px;
}

.user-info .phone-number {
    margin-top: 5px;

    font-weight: 200;

}

.user-info .right {
    margin-left: 10px;

    text-align: left;
}

.user-info img {
    border-radius: 50%;
}

.nav-list {
    text-align: left;
}
</style>